<div id=""huge_contatiner>
<div>
    <h3>Наш сегодняшний заказ <a href="<?php echo url_for('@view_statistic');?>" style="float: right; font-size: 16px;">Список обжор</a></h3>
</div>
<?php foreach($users_order_ids as $u_id): ?>
<div>
    <h3><?php $name = Doctrine::getTable('SfGuardUser')->findOneBy('id', $u_id); echo $name->getUsername(); ?></h3>
    <table class="view_products_table">
        
        <?php
        
        $user_total = 0;
        $complete_order_of_user = Doctrine::getTable('orders')->getMyOrder($u_id);
        $complete_order_combined_of_user = Doctrine::getTable('orders_combined')->getMyCombinedOrder($u_id);
            ?>
    <?php foreach($complete_order_of_user as $ord) : ?>
      
        <tr id="<?php echo $ord->getId(); ?>">
            <td><?php echo $ord->getProduct()->getName(); ?></td>
            <td><?php echo $ord->getProduct()->getCategory()->getName(); ?></td>
            <td><?php echo $ord->getQuantity(); ?> порций</td>
            <td><?php echo $ord->getTotal(); $user_total += $ord->getTotal(); ?> сом</td>
            <?php if ($u_id == $currentId): ?>
            <td><a class="delete_from_orders" href="#" tbl="orders" oid="<?php echo $ord->getId(); ?>">Удалить</a></td>
            <?php endif; ?>
        </tr>
    <?php endforeach; ?>
    <?php foreach($complete_order_combined_of_user as $ord) : ?>
        <tr>
            <td><?php 
            if ($ord->getProduct()->getCategory()->getId() != 6) {
                echo $ord->getProduct()->getName()." + ".$ord->getProductcon()->getName();
            } else { echo $ord->getProduct()->getName(); }
            ?></td>
            <td></td>
            <td><?php echo $ord->getQuantity(); ?> порций</td>
            <td><?php echo $ord->getTotal(); $user_total += $ord->getTotal(); ?> сом</td>
            <?php if ($u_id == $currentId): ?>
            <td><span><a class="delete_from_orders" href="#" tbl="orders_combined" oid="<?php echo $ord->getId(); ?>">Удалить</a></span></td>
            <?php endif; ?>
        </tr>
    <?php endforeach;?>
    </table>
    <br/>
    <div id="total_per_my_order">
        <br/>
        <b>Всего <?php echo $user_total; ?> сом</b>
    </div>
</div>
<?php endforeach; ?>
<br/>
<?php if(count($orders) != 0 || count($orders_combined) != 0) : ?>
<table class="view_products_table">
    <tr>
        <th><a href="<?php echo url_for("@view_order?sortbyname=".$username_sort) ?>">Название</a></th>
        <th><a href="<?php echo url_for("@view_order?sortbycategory=".$category_sort) ?>">Категория</a></th>
        <th>Количество</th>
        <th>Цена</th>
    </tr>
<?php 
    $total = 0;
    foreach ($orders as $order):
?>
    <tr>
        <td><?php echo $order['Product']['name']; ?></td>
        <td><?php echo $order['Product']['Category']['name']; ?></td>
        <td><?php echo $order['quantity']; ?> порций</td>
        <td><?php echo $order['total']; $total += $order['total']; ?> сом</td>
    </tr>
    <?php endforeach; ?>
    <?php foreach ($orders_combined as $combined_order): ?>
    <tr>
        <td><?php
        if ($combined_order['Product']['Category']['id'] != 6) {
            echo $combined_order['Product']['name'] . " + " . $combined_order['Productcon']['name'];
        } else { echo $combined_order['Product']['name']; }
         ?></td>
        <td></td>
        <td><?php echo $combined_order['quantity']; ?> порций</td>
        <td><?php echo $combined_order['total']; $total += $combined_order['total']; ?> сом</td>
    </tr>
    <?php endforeach; ?>
</table>
<div id="total_per_order">
    <br/>
    <b>Итого <?php echo $total; ?> сом</b>
</div>
<?php if (count($users_order_ids) != 0): ?>
<div class="user_summ_list">
    <h3>Кто сколько должен? </h3>
    <?php foreach($users_order_ids as $u_id) : ?>
    <div>
        <label><?php $name = Doctrine::getTable('SfGuardUser')->findOneBy('id', $u_id); echo $name->getUsername(); ?></label>
        <?php 
            $sum_of_combined_orders = Doctrine::getTable('orders_combined')->getOrderSumOfUser($u_id);
            $t = $sum_of_combined_orders->toArray();
            
            $sum_of_orders = Doctrine::getTable('orders')->getOrderSumOfUser($u_id);
            $t2 = $sum_of_orders->toArray();
            
            $final_sum = $t2[0]['total'] + $t[0]['total'];
        ?>
        <span><?php echo $final_sum; ?> сомей</span>
        <div class="clear"></div>
    </div>
    <?php endforeach;?>
</div>
<? endif; ?>
<div>
<!--    <a id="order_finished" href="<?= url_for('@order_after_check') ?>">Свериться</a>-->
</div>
<?php else: ?>
    <div>
        На сегодня заказов еще не было, но ты можешь <a href="<?= url_for('@viewproducts') ?>">стать первым</a> :)
    </div>
<?php endif;?>
</div>
